package quwei;

public class Test4_4_c {
    public static void main(String[] args) {

    }

    public static int deitDistance(String str1, String str2) {
        int len1 = str1.length();
        int len2 = str2.length();
        int[][] d = new int[len1 + 1][len2 + 1];
        for (int i = 0; i < len1; i++) {
            d[i][0] = i;
        }
        for (int j = 0; j < len2; j++) {
            d[0][j] = j;
        }
        for (int i = 1; i < d.length; i++) {
            for (int j = 1; j < d[i].length; j++) {
                int diff;
                if (str1.charAt(i - 1) == str2.charAt(j - 1)) {
                    diff = 0;
                } else {
                    diff = 1;
                }
                int temp = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1);
                d[i][j] = Math.min(temp, d[i - 1][j - 1] + diff);
            }
        }

        return d[len1][len2];
    }

}
